<template>
	<view class="">
		<view class="footer flex justify-around align-center c_6 font-sm">
			<view class="flex align-center justify-center" @click="favorites(1, favMsg.like_status)">
				<u-icon :name="favMsg.like_status == 1 ? 'thumb-up-fill' : 'thumb-up'" :color="favMsg.like_status == 1 ? '#CF1526' : '#666'" size="22"></u-icon>
				<text>({{ favMsg.like_num || 0 }})</text>
			</view>
			<text>|</text>
			<view class="flex align-center justify-center" @click="favorites(2, favMsg.collect_status)">
				<u-icon :name="favMsg.collect_status == 1 ? 'star-fill' : 'star'" :color="favMsg.collect_status == 1 ? '#CF1526' : '#666'" size="22"></u-icon>
				<text>({{ favMsg.collect_num || 0 }})</text>
			</view>
			<text>|</text>
			<view class="flex align-center justify-center">
				<button class="bottom_share flex justify-center c_6 font-sm p-0" open-type="share" @click="favorites(3)">
					<u-icon name="share-square" :color="favMsg.share_status == 1 ? '#CF1526' : '#666'" size="22"></u-icon>
					<text>({{ favMsg.share_num || 0 }})</text>
				</button>
			</view>
		</view>
		<!-- 登录弹窗 -->
		<login-popup v-if="loginShow" :login-show="loginShow" :popup-title="popupTitle" @close="loginShow = false" @loginSuccess="loginSuccess"></login-popup>
	</view>
</template>

<script>
import loginPopup from '@/components/login_popup/login_popup.vue';
import { sneclogOperate } from '@/api/home/home.js';
export default {
	components: { loginPopup },
	props: {
		// 点赞/收藏/分享 数量
		numdata: {
			type: Object,
			default: {}
		},
		// 类型： 1 视频，2 ：直播，3：新闻
		type: {
			type: Number,
			default: 3
		},
		// 平台： 0 掌上所比  1 光伏网， 2 储能
		platform: {
			type: Number,
			default: 0
		},
		newId: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			loginShow: false,
			popupTitle: '',
			favMsg: null
		};
	},
	watch: {
		numdata: {
			handler(newV, oldV) {
				this.favMsg = this.numdata;
				// console.log('newV==', newV);
			},
			deep: true,
			immediate: true
		}
	},
	methods: {
		favorites(type, state) {
			if (!uni.getStorageSync('userInfo').hasLogin) {
				if (type == 1) {
					this.loginShow = true;
					this.popupTitle = '登录后可点赞';
				} else if (type == 2) {
					this.loginShow = true;
					this.popupTitle = '登录后可收藏';
				}
				return;
			}
			let msg = {
				type: this.type,
				platform: this.platform,
				id: this.newId,
				uid: uni.getStorageSync('userInfo').userId,
				token: uni.getStorageSync('userInfo').token,
				class: type, //1：点赞，2 收藏，3 分享
				status: state == 1 ? 0 : 1 //0 取消， 1 ：成功
			};
			sneclogOperate(msg).then(res => {
				uni.$u.toast(res.msg);
				if (res.code == 0) {
					this.favMsg = res.new_operate;
				}
			});
		},
		// 登陆成功更新点赞收藏状态
		loginSuccess() {
			this.$emit('loginSuccess');
		}
	}
};
</script>

<style lang="scss" scoped>
.footer {
	width: 100%;
	transform: translateY(10rpx);
	view {
		width: calc(100% / 3);
	}
}
</style>
